<?php

namespace Orqlog\YacampaignDrawLaravel\Domain\Repository;

trait RepositoryTraits
{
    
    protected function addItem($obj) 
    {
        $tId = $obj->getId();
        $fItem = $this->find($tId);

        if (is_int($tId) && !is_null($fItem)) {
            // update existing record
            $item = $this->makeItem($obj, $fItem);
        } else {
            // insert new onw
            $item = $this->makeItem($obj);
        }
        $item->save();

        $obj->setId($item->id);
        return $obj;
    }
}